package com.kim.client.strategy;


import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.kim.client.abs.AbsMessageStrategy;
import com.kim.client.enums.MessageContentTypeServerEnum;
import com.kim.client.factory.StrategyBeanFactory;
import com.kim.client.interfaces.MessageStrategy;
import com.kim.common.entity.message.MessageInfo;
import com.kim.common.enums.GlobalExceptionEnum;
import io.smallrye.mutiny.Uni;
import jakarta.inject.Inject;
import jakarta.websocket.Session;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import static com.kim.common.enums.GlobalExceptionEnum.MESSAGE_CONTENT_TYPE_ERROR;
import static com.kim.common.enums.GlobalExceptionEnum.MESSAGE_CONTENT_TYPE_NOT_NULL;


/**
 * 一对一消息处理
 */
@Slf4j
public class PersonMessageStrategy extends AbsMessageStrategy {

    @Inject
    StrategyBeanFactory factory;

    @Override
    public GlobalExceptionEnum sendMessage(MessageInfo messageInfo, Session session) {

        if (StringUtils.isNotBlank(String.valueOf( messageInfo.getMessageContentType()))) {
            MessageContentTypeServerEnum messageStrategyEnum = MessageContentTypeServerEnum.getServiceById(messageInfo.getMessageContentType());
            if (messageStrategyEnum == null) {
                return(MESSAGE_CONTENT_TYPE_ERROR);
            }

            MessageStrategy messageServerByName = factory.getProcessor(messageStrategyEnum.getService());
            messageServerByName.onMessage(messageInfo, session);
        }else {
            return (MESSAGE_CONTENT_TYPE_NOT_NULL);

        }
        return null;
    }

    /**
     * 后续校验是否有消息发送的权限(是否是好友等。。。)
     * @param messageInfo
     * @param session
     * @throws Exception
     */
    @Override
    protected GlobalExceptionEnum sendMessageBefore(MessageInfo messageInfo, Session session)  {

        return null;
    }

    @Override
    protected GlobalExceptionEnum sendMessageAfter(MessageInfo messageInfo, Session session) {
        // 保存消息
        return null;
    }
}
